<?php
/**
 * tpshop
 * ============================================================================
 * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.tp-shop.cn
 * ----------------------------------------------------------------------------
 * Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
 * ============================================================================
 * Author: 当燃
 * Date: 2015-09-09
 */
namespace Admin\Controller;
use Admin\Logic\ArticleCatLogic;

class QuestionAnswerController extends BaseController
{

    /**
     * 列表
     */

    public function index()
    {
        $count = M('question_answer')->count();// 查询满足要求的总记录数
        $Page = new \Think\Page($count, 10);// 实例化分页类 传入总记录数和每页显示的记录数
        $show = $Page->show();// 分页显示输出
        $qa_list = M('question_answer')->where()->order('id DESC')->limit($Page->firstRow . ',' . $Page->listRows)->select();
        $this->assign('lists', $qa_list);
        $this->assign('page', $show);
        $this->display();
    }


    /**
     * 添加/编辑
     */

    public function add_qa_info()
    {
        $id = I('id');
        if (IS_POST) {
            $data = I();
            $data['add_time'] = time();
            if ($id) {
                $res = M('question_answer')->save($data);
            } else {
                $res = M('question_answer')->add($data);
            }
            if ($res) {
                $this->success("操作成功", U('index'));
            } else {
                $this->error("操作失败，请重试！", U('index'));
            }
            EXIT;
        }
        if ($id) {
            $qa_info = M('question_answer')->where("id=$id")->find();
            $this->assign('qa_info', $qa_info);
        }
        $this->display();
    }


    /**
     * 删除
     */
    public function qa_del()
    {
        $id = I('id');
        $res = M('question_answer')->where("id=$id")->delete();
        if ($res) {
            $this->success("删除成功", U('index'));
        } else {
            $this->error("删除失败，请重试！", U('index'));
        }
    }
}